using System;
using System.Reflection;
using UnityEngine;
using UnityEngine.UI;
using static System.Net.Mime.MediaTypeNames;

public class ScreenController : MonoBehaviour
{
    private string[] PreSet;
    private  int IndexNow;
    public UnityEngine.UI.Text mText;
    private RenderTexture render;

    private void Awake()
    {
        PreSet = new string[4];
        PreSet[0] = "2560*1440";
        PreSet[1] = "1920*1080";
        PreSet[2] = "1280*720";
        PreSet[3] = "720*480";
    }
    void Start()
    {
        string[] rs = Settings.setting.opa[1].Split('*');
        int w = int.Parse(rs[0]);
        int h = int.Parse(rs[1]);
        Screen.SetResolution(w, h, true);
        IndexNow = int.Parse(Settings.setting.opa[2]);
        mText.text = PreSet[IndexNow];
    }


    public void onDown()
    {
        if (IndexNow + 1 >= 4) return;
        IndexNow++;
        ChangeScreen();
    }

    public void onUp()
    {
        if (IndexNow - 1 < 0) return;
        IndexNow--;
        ChangeScreen();
    }

    private void ChangeScreen()
    {
        mText.text = PreSet[IndexNow];
        var text = PreSet[IndexNow];
        Settings.setting.opa[1] = text;
        Settings.setting.opa[2] = IndexNow.ToString();
        string[] rs = text.Split('*');
        int w = int.Parse(rs[0]);
        int h = int.Parse(rs[1]);
        Screen.SetResolution(w, h, true);

    }


}
